package com.iccct.feign.common;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * comment
 *
 * @author iccct (taowutt1@gmail.com)
 * @since 2021-07-26  17:01
 */
@AllArgsConstructor
@Getter
public enum ERRORResponse {

    QUERY_ERROR(400, "查询失败"),
    IMPORT_ERROR(400, "导入失败"),
    TYPE_ERROR(400, "文件类型错误"),
    INSERT_ERROR(400, "新增失败"),
    ILLEGAL_ARGUMENT_ERROR(400, "参数错误"),
    LOGIN_ERROR(400, "登录失败,帐号不存在或者密码不正确"),
    REGIST_ERROR(400, "注册失败"),
    UPDATE_ERROR(400, "修改失败"),
    TO_LOGIN(400, "该账号一登录"),
    LOGOUT_ERROR(400, "退出失败"),
    DELETE_ERROR(400, "删除失败"),
    LOGIN_AGAIN(401, "请重新登录"),
    INSERT_EXIST(400, "前端唯一标识已存在"),
    REGIST_ACCOUNT_EXIST(400, "该帐号以存在"),
    NO_AUTH_OPERATE(400, "无权限操作"),
    UNKNOWN_ERROR(400, "未知错误,请联系管理员！"),
    ;
    private final Integer code;
    private final String msg;


    public <T> Response<T> toResponse(T data) {
        if (data == null) {
            return new Response<T>(this.code, this.msg, null);
        }
        return new Response<T>(this.code, this.msg, data);
    }

    public <T> Response<T> toResponse() {
        return new Response<T>(this.code, this.msg, null);
    }

}
